﻿namespace Steamworks
{
    using System;
    using System.Runtime.InteropServices;

    public static class SteamController
    {
        public static bool GetControllerState(uint unControllerIndex, out SteamControllerState_t pState)
        {
            InteropHelp.TestIfAvailableClient();
            return NativeMethods.ISteamController_GetControllerState(unControllerIndex, out pState);
        }

        public static bool Init(string pchAbsolutePathToControllerConfigVDF)
        {
            InteropHelp.TestIfAvailableClient();
            using (InteropHelp.UTF8StringHandle handle = new InteropHelp.UTF8StringHandle(pchAbsolutePathToControllerConfigVDF))
            {
                return NativeMethods.ISteamController_Init(handle);
            }
        }

        public static void RunFrame()
        {
            InteropHelp.TestIfAvailableClient();
            NativeMethods.ISteamController_RunFrame();
        }

        public static void SetOverrideMode(string pchMode)
        {
            InteropHelp.TestIfAvailableClient();
            using (InteropHelp.UTF8StringHandle handle = new InteropHelp.UTF8StringHandle(pchMode))
            {
                NativeMethods.ISteamController_SetOverrideMode(handle);
            }
        }

        public static bool Shutdown()
        {
            InteropHelp.TestIfAvailableClient();
            return NativeMethods.ISteamController_Shutdown();
        }

        public static void TriggerHapticPulse(uint unControllerIndex, ESteamControllerPad eTargetPad, ushort usDurationMicroSec)
        {
            InteropHelp.TestIfAvailableClient();
            NativeMethods.ISteamController_TriggerHapticPulse(unControllerIndex, eTargetPad, usDurationMicroSec);
        }
    }
}

